/**
 * 
 */
package com.zc.BankCreditManagement.ServiceImpl;

import com.zc.BankCreditManagement.DAO.EmailVerifyDAO;
import com.zc.BankCreditManagement.JavaBean.EmailVerify;
import com.zc.BankCreditManagement.Service.EmailVerifyService;

/**
 * @author ZhangCheng
 * @time 2019年9月28日
 */
public class EmailVerifyServiceImpl implements EmailVerifyService {
	EmailVerifyDAO eVDAO;

	public EmailVerifyServiceImpl() {
		this.eVDAO = new EmailVerifyDAO();
	}
	/**
	 * 判断验证码是否正确
	 */
	public String isCodeRight(int peoId,String code) {
		if(this.eVDAO.isCodeOverDueById(peoId)) {
			return "您的验证码过期，请重新获取！";
		}else {
			if(code.equals(this.eVDAO.getEmailVerifyById(peoId, true).getPeoVerCode())){
				return "Yes";
			}else{
				return "您的验证码输入的不正确，请重试！";
			}
		}
	}
	/**
	 * 保存新验证码
	 */
	public String saveThisCode(EmailVerify eV,int validityMin) {
		if(this.eVDAO.getEmailVerifyById(eV.getPeoId(), true)==null) {
			if(this.eVDAO.insertNewCode(eV,validityMin)==1) {
				return "新增 成功";
			}else {
				return "新增 失败";
			}
		}else {
			if(1==this.eVDAO.updateCodeOverDueById(eV.getPeoId(), eV.getPeoVerCode(),validityMin)){
				return "更新 成功";
			}else{
				return "更新 失败";
			}
		}
		
	}

}
